package com.itheima.mp.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.domain.query.UserQuery;
import com.itheima.mp.domain.vo.UserVO;
import com.itheima.mp.mapper.UserMapper;
import com.itheima.mp.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public List<UserVO> queryList(UserQuery userQuery) {
        QueryWrapper<User> userQueryWrapperww = new QueryWrapper<>();
        LambdaQueryWrapper<User> lambdaQueryWrapper = userQueryWrapperww.lambda()
                .like(StrUtil.isNotBlank(userQuery.getName()), User::getUsername, userQuery.getName())
                .ge(userQuery.getMinBalance() != null, User::getBalance, userQuery.getMinBalance());
        //设置balance字段加100
//        this.lambdaUpdate().setSql("banlance=banlance+11");
        return BeanUtil.copyToList(this.list(lambdaQueryWrapper), UserVO.class);
    }
}
